{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ce033a27-6dbd-4cf5-9e2b-4025532d972f",
   "metadata": {},
   "source": [
    "# 训练前处理图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "903ff968-1c2a-40f8-9842-c8856bc80f6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取数据后，要处理加工数据后，才可以训练"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4c939f6-7061-463f-a8f1-fab4b0277e23",
   "metadata": {},
   "source": [
    "## config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a58df3a5-aa4d-4fce-9514-36ff7b6f68d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 训练目录\n",
    "train_dir = \"/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean4\"\n",
    "# 数据来源目录\n",
    "original_dir = \"/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/original\"\n",
    "\n",
    "generator_num = 15"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eea1985b-d8e2-41ce-89c7-b8682ea48c53",
   "metadata": {},
   "source": [
    "## 测试导入库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6afbe20e-da71-4264-b666-d2301e328256",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test: ./img/a\n"
     ]
    }
   ],
   "source": [
    "from train.tools.img import Img\n",
    "img1 = Img()\n",
    "img1.test(\"./img/a\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c60802e-1c0d-4dd8-9bee-d4f87957579f",
   "metadata": {},
   "source": [
    "## 删除数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2ae75a15-ab1f-4b2e-8fcf-bba422e2e8d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除数据\n",
    "import os, sys\n",
    "import shutil\n",
    "\n",
    "def clean_data(temp_datasets_dir):\n",
    "    if os.path.exists(temp_datasets_dir):\n",
    "        shutil.rmtree(temp_datasets_dir)\n",
    "    os.makedirs(temp_datasets_dir)\n",
    "\n",
    "clean_data(train_dir)\n",
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa24481c-9e6f-4fc6-ae34-58a8d3d1fea5",
   "metadata": {},
   "source": [
    "## 选取数据"
   ]
  },
  {
   "cell_type": "raw",
   "id": "d791d015-6c00-4995-b346-563aae9feb4d",
   "metadata": {},
   "source": [
    "from train.tools.img.copy_file import copy_file ,multiple_dir\n",
    "\n",
    "file_dir = \"/Users/liampro/Downloads/dataLake/images/图像分类/垃圾分类/DATASET_clean/TEST/O\"\n",
    "tar_dir = \"/Users/liampro/Downloads/dataLake/images/图像分类/垃圾分类/DATASET_clean/temp/O\"\n",
    "num = 100\n",
    "copy_file(file_dir=file_dir,tar_dir=tar_dir,num=num,step =1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e4bb60ec-c794-42e7-b2b6-5f1be70296e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from train.tools.img.copy_file import copy_file ,multiple_dir\n",
    "\n",
    "num = 100\n",
    "\n",
    "multiple_dir(root_dir=original_dir,outdir=train_dir,num=num,step =1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "033187db-db5e-4bde-8920-9b5e63d59ca4",
   "metadata": {},
   "source": [
    "## 清理单个目录"
   ]
  },
  {
   "cell_type": "raw",
   "id": "935eb43e-db64-4abd-b128-c8b356aeb64b",
   "metadata": {},
   "source": [
    "from train.tools.img import Img\n",
    "\n",
    "path = train_dir\n",
    "path1 =path+\"/R\"\n",
    "\n",
    "img = Img(clean=True,convert=True,resize=True,generator=True,rename=True)\n",
    "\n",
    "img.clean_dir_img(path= path1,size = [224,224])\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e73cbefb-60fa-4082-8be9-355ae94f18f4",
   "metadata": {},
   "source": [
    "## 清理2层目录数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "87a9f271-c191-4efd-b29c-0279de2390df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[OSError]:/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/30_.DS_Store\n",
      "[clean_dir remove]: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/30_.DS_Store \n",
      "[clean_dir: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right end]\n",
      "[OSError]:/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man/7_.DS_Store\n",
      "[clean_dir remove]: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man/7_.DS_Store \n",
      "[clean_dir: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man end]\n",
      "[OSError]:/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/7_.DS_Store\n",
      "[clean_dir remove]: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/7_.DS_Store \n",
      "[clean_dir: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left end]\n",
      "[OSError]:/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/3_.DS_Store\n",
      "[clean_dir remove]: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/3_.DS_Store \n",
      "[clean_dir: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward end]\n",
      "[clean_multiple_dir end]\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/1_下载.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/28_images.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/3_images3.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/13_images666.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/2_images9995666.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/27_images999.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/10_下载 (1).png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/21_canva-MACKYZpxq1w.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/7_images (1).png\n",
      "[png to jpg :convert_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right end]\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man/6_10f2af4e6e3640078127ab81a34f1275.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man/11_下载22.png\n",
      "[png to jpg :convert_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man end]\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/18_images4dfs.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/4_t01442d0c02be7a4747.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/2_canva-MAB60bAMMZE.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/1_下载.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/27_images4dgh.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/17_images3df.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/11_下载 (1)rrrtr.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/0_下载 (1)认455.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/33_images4ggg.png\n",
      "[png to jpg :convert_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left end]\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/27_下载1234566.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/20_images2345566.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/2_5936.png_300.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/21_16pic_7143550_b.png\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/anaconda3/envs/k210v37/lib/python3.7/site-packages/PIL/Image.py:974: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images\n",
      "  \"Palette images with Transparency expressed in bytes should be \"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/12_images56565.png\n",
      "ok: /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/8_imagestyyu.png\n",
      "[png to jpg :convert_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward end]\n",
      "[png to jpg :convert_multiple_dir end]\n",
      "[resize_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right/19_unnamed.jpeg end]\n",
      "[resize_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man/6_10f2af4e6e3640078127ab81a34f1275_png.jpg end]\n",
      "[resize_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left/22_1_210615163754_1.jpeg end]\n",
      "[resize_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward/25_下载 (1).jpeg end]\n",
      "[resize_multiple_dir end]\n"
     ]
    }
   ],
   "source": [
    "from train.tools.img import Img\n",
    "\n",
    "path = train_dir\n",
    "\n",
    "img = Img(clean=True,convert=True,resize=True,generator=False,rename=False,generator_num=generator_num)\n",
    "\n",
    "img.clean_multiple_dir_img(root_dir= path,size = [224,224])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f4356200-0c19-44ca-85ab-1cefe6f06ac0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[generator_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right end]\n",
      "[generator_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man end]\n",
      "[generator_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left end]\n",
      "[generator_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward end]\n",
      "[generator_multiple_dir end]\n"
     ]
    }
   ],
   "source": [
    "# generator\n",
    "from train.tools.img import Img\n",
    "\n",
    "img2 = Img(clean=False,convert=False,resize=False,generator=True,rename=False,generator_num=generator_num)\n",
    "img2.clean_multiple_dir_img(root_dir= train_dir,size = [224,224])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "92fcf976-8fe1-4a36-bf0c-21e73aca6b0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[rename_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/right end]\n",
      "[rename_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/man end]\n",
      "[rename_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/left end]\n",
      "[rename_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/forward end]\n",
      "[rename_multiple_dir end]\n"
     ]
    }
   ],
   "source": [
    "# rename\n",
    "from train.tools.img import Img\n",
    "\n",
    "img2 = Img(clean=False,convert=False,resize=False,generator=False,rename=True,generator_num=generator_num)\n",
    "img2.clean_multiple_dir_img(root_dir= train_dir,size = [224,224])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "89d6c7bb-e140-42ff-8c0a-cc9a81716603",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: '/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/3-man'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m/var/folders/_l/dffcyljj723fg4wbqfxfqv640000gn/T/ipykernel_10903/1354549991.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimg\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mImg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mimg2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mImg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclean\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mresize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mgenerator\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mrename\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mgenerator_num\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mimg2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclean_dir_img\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mtrain_dir\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m\"/3-man\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msize\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m224\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m224\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/Downloads/pro/git/ai-test/k210/k210_train/train/tools/img/__init__.py\u001b[0m in \u001b[0;36mclean_dir_img\u001b[0;34m(self, path, outdir, size)\u001b[0m\n\u001b[1;32m     36\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mclean_dir_img\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"./img/a\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0moutdir\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m224\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m224\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     37\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclean\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 38\u001b[0;31m             \u001b[0mclean_dir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mremove_error_img\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmin_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     39\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     40\u001b[0m             \u001b[0mconvert_dir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/Downloads/pro/git/ai-test/k210/k210_train/train/tools/img/clean.py\u001b[0m in \u001b[0;36mclean_dir\u001b[0;34m(path, remove_error_img, min_size)\u001b[0m\n\u001b[1;32m     34\u001b[0m \u001b[0;31m#clean_dir(\"./img/a\",True,[10,10])\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     35\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mclean_dir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"./img/a\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mremove_error_img\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmin_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m     \u001b[0mimg_dir\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     37\u001b[0m     \u001b[0;32mfor\u001b[0m \u001b[0mimg\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mimg_dir\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     38\u001b[0m         \u001b[0mfile_path\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#path + img\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/3-man'"
     ]
    }
   ],
   "source": [
    "# 微调\n",
    "from train.tools.img import Img\n",
    "img2 = Img(clean=True,convert=True,resize=True,generator=True,rename=False,generator_num=20)\n",
    "img2.clean_dir_img(path= train_dir+\"/3-man\",size = [224,224])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d35dd96-bccc-49ec-b711-c7600c84f5a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from train.tools.img.generator import generator_dir\n",
    "\n",
    "generator_dir(train_dir+\"/3-man\",1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8575884c-38ff-464c-8c4a-2dd29bab2281",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[rename_dir /Users/liampro/Downloads/dataLake/images/图像分类/交通标识/clean3/3-man end]\n"
     ]
    }
   ],
   "source": [
    "from train.tools.img.rename import rename_dir\n",
    "\n",
    "rename_dir(train_dir+\"/3-man\",\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab5946d2-6eb0-42c8-a92d-b8a0f3502a49",
   "metadata": {},
   "source": [
    "## 图片显示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16a29a06-ba0e-48b8-a0a8-5826730d9956",
   "metadata": {},
   "outputs": [],
   "source": [
    "from train.tools.img.show import show_multiple_dir,show_img"
   ]
  },
  {
   "cell_type": "raw",
   "id": "85046799-7d26-4668-9ef3-e9c418fce635",
   "metadata": {},
   "source": [
    "# 显示1个目录\n",
    "path1 = train_dir+\"/R\"\n",
    "\n",
    "show_img(path1,num=4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a921f2db-0c12-468b-a334-13103264cab8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 显示2层目录\n",
    "path = train_dir\n",
    "\n",
    "show_multiple_dir(path,num=4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40a95e63-4b6f-4bd5-977d-e5c41aeac941",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
